﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="LeaveQuota.aspx.cs" Inherits="AttendanceWebForm_LeaveQuota" %>
<script runat="server">
    protected void gv_DataBinding(object sender, EventArgs e)
    {
        var sql = new StringBuilder();
        var dbparams = new List<DBParameter>();

        sql.AppendFormat(string.Format(@"SELECT h.* FROM Holiday h WHERE HolidayGroupID = @HolidayGroupID "));

        if (string.IsNullOrEmpty(listHolidayGroupID.Text))
        {
            dbparams.Add(new DBParameter("HolidayGroupID", ""));
        }
        else
        {
            dbparams.Add(new DBParameter("HolidayGroupID", listHolidayGroupID.Text));
        }

        if (ddlYY.Text.Length > 0)
        {
            sql.AppendFormat("AND Year(Date) = Year(@Date) ");
            dbparams.Add(new DBParameter("Date", ddlYY.Value));
        }

        var db = new DB("Attendance");
        var dt = db.Execute(sql.ToString(), dbparams.ToArray());

        (sender as DataBoundControl).DataSource = dt;

    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:PlaceHolder ID="plQuery" runat="server">
        <table>
            <tr>
                <td class="label">
                    <asp:Localize ID="Localize1" runat="server" Text="<%$Resources: Holiday, HolidayGroupID %>"></asp:Localize>
                </td>
                <td class="text">
                    <asp:TextBox ID="txtHolidayGroupID" runat="server"></asp:TextBox>
                    <asp:Panel ID="pnlHolidayGroupID" runat="server" SkinID="Popup" Width="300">
                        <asp:UpdatePanel ID="upHolidayGroupID" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>
                                <My:ListPopup ID="listHolidayGroupID" runat="server" OnDataBinding="listHolidayGroupID_DataBinding"
                                    Clearable="true"></My:ListPopup>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </asp:Panel>
                    <ajax:PopupControlExtender ID="peHolidayGroupID" runat="server" TargetControlID="txtHolidayGroupID"
                        PopupControlID="pnlHolidayGroupID" Position="Bottom">
                    </ajax:PopupControlExtender>
                </td>
                <td class="label">
                    <asp:Localize ID="Localize2" runat="server" Text="<%$Resources: lblYY.Text %>"></asp:Localize>
                </td>
                <td class="text">
                    <My:YY ID="ddlYY" runat="server" Optional="false" YearPlus="1" />
                </td>
                <td class="text">
                    <asp:LinkButton ID="lknSample" runat="server" Text="<%$Resources: lknSample.Text %>"
                         OnClick="lknSample_Click"></asp:LinkButton>
                </td>
                <td class="text">
                    <asp:FileUpload ID="fuDate" runat="server" />
                    <asp:Button ID="btnImport" runat="server" Text="<%$Resources: Form, btnImport %>" OnClick="btnImport_Click" />
                    <ajax:ConfirmButtonExtender ID="cbImport" runat="server" TargetControlID="btnImport" ConfirmText="<%$Resources: Form, cb %>">
                    </ajax:ConfirmButtonExtender>
                    <asp:Button ID="btnQuery" runat="server" Text="<%$Resources: Form, btnQuery %>" OnClick="btnQuery_Click" />
                    <My:ClearButton ID="ClearButton1" runat="server"></My:ClearButton>
                </td>
            </tr>
        </table>
    </asp:PlaceHolder>
    <My:MyGridView ID="gv" runat="server" OnDataBinding="gv_DataBinding" OnRowCommand="gv_ItemCommand"
        DataKeyNames="HolidayGroupID, Date">
        <Columns>
            <asp:TemplateField HeaderText="<%$Resources: EmpData, EmpID   %>">
                <ItemTemplate>
                    <%# LocManager.Current.GetText("EmpData", "EmpName", Eval("HolidayGroupID"))%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: LeaveQuota, Amount   %>">
                <ItemTemplate>
                    <%# Eval("Date", "{0:d}") %>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </My:MyGridView>
</asp:Content>

